﻿using Biomedica.Graphics;
using Biomedica.Propability.StateMachine;
using KinectWindows.Math;
using Microsoft.Kinect;
using NuiDicomPlayer.Nui.Gestures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
namespace NuiDicomPlayer.Nui.NavigationEngine
{
    public delegate void StageChanged(State oldState,State newState);
    public abstract class NuiNavigator
    {
        
        StateContext Context;
        public StageChanged OnStageChanged;
        private Dictionary<String, Boolean> StateGards = new Dictionary<string, bool>();
       
        
        public NuiNavigator()
        {

            //#region StateDiagram builder
            //#region Create States
            //List<State> StateCollections = new List<State>();
            //StateCollections.Add(new State("instage"));// No action performed
            //StateCollections.Add(new State("outstage"));// No action performed
            //StateCollections.Add(new State("SliceMode"));// Navigate throw Slices
            //StateCollections.Add(new State("BrightnessMode"));// Change Brightness
            //StateCollections.Add(new State("ContrastMode"));// Change Contrast
            //StateCollections.Add(new State("ZoomInMode"));// Zoom in
            //StateCollections.Add(new State("ZoomOutMode"));// Zoom out
            //StateCollections.Add(new State("PanMode"));// Pan Left.Right,Up,Down
            //StateCollections.Add(new State("nuizone"));
            //Context = StateMachineFactory.CreateStateMachine(StateCollections.ToArray());
            //#endregion
            //#region init Envirunment Regesters
            //Context.initaliseTable(new String[] {"userinstage","useroutstage","inactivezone","outactivezone", "saychangeslicemode", "saychangebrightness","saychangecontrast","sayzoom","sayzoomin","sayzoomout","c","sayquit","increase"
            //                                      ,"righthandmoveleft","righthandmoveright","righthandmoveup","righthandmovedown"
            //                                      ,"lefthandmoveleft","lefthandmoveright","lefthandmoveup","lefthandmovedown",
            //                                      "isinnuizone","isnotinnuizone"
            //});
            //#endregion
            //#region Transtions
            //Context.getStateMachineEngine().AddTransition("instage", "outstage", "useroutstage");
            //Context.getStateMachineEngine().AddTransition("outstage", "instage", "userinstage");
            //Context.getStateMachineEngine().AddTransition("instage", "nuizone", "isinnuizone");
            //Context.getStateMachineEngine().AddTransition("nuizone", "instage", "isnotinnuizone");
            //Context.getStateMachineEngine().AddTransition("nuizone", "outstage", "useroutstage");
            //#endregion
            //#region Transtion Callback
            //Context.getStateMachineEngine().SetOnDoCallback(OnUserInstage,@"instage");
            //Context.getStateMachineEngine().SetOnEnterCallback(OnUserEnteredStage, @"instage");
            //Context.getStateMachineEngine().SetOnEnterCallback(OnUserExitedStage, @"outstage");
            //Context.getStateMachineEngine().SetOnDoCallback(OnUserOutstage, @"outstage");

            //Context.getStateMachineEngine().SetOnEnterCallback(OnUsergandsEnteredNuiZone, "nuizone");
            //Context.getStateMachineEngine().SetOnDoCallback(OnUserhandsInNuiZone, "nuizone");
            //Context.getStateMachineEngine().SetOnExitCallback(OnUserExitedNuiStage, "nuizone");



            //#endregion
            //#endregion

        }
        /// <summary>
        /// The drived classes must creart the state machine and fill the State Gard Buffer
        /// </summary>
        public abstract void CreateStateMachine();
        /// <summary>
        /// Update The Navigation State Machine
        /// </summary>
        public virtual void Update()
        {
            State old = Context.CurrentState;
            Context.getStateMachineEngine().Update(Context);
            State newS = Context.CurrentState;
            if (OnStageChanged != null)
                OnStageChanged(old, newS);
        }
        /// <summary>
        /// Reset the State Regesters to false
        /// </summary>
        public void Reset()
        {
            String[] Keys = StateGards.Keys.ToArray();
            for (int i = 0; i < Keys.Length; i++) StateGards[Keys[i]] = false;
            
        }
        
    }

    
}
